import { reqGetSearchInfo } from '@/api'
// search模块的小仓库
// state:仓库存储数据的地方
const state = {
    searchList: {}
};
// mutations:修改state的唯一手段
const mutations = {
    GETSEARCHLIST(state, searchList) {
        state.searchList = searchList
    }
};
// 处理action,可以书写自己的业务逻辑，也可以处理异步
const actions = {
    // 获取search模块的数据
    async getSearchList({ commit }, params = {}) {
        let result = await reqGetSearchInfo(params)
        if (result.code == 200) {
            commit("GETSEARCHLIST", result.data)
        }
    }
};
// getters:理解为计算属性，用于简化仓库数据，让组件获取仓库的数据更为方便
const getters = {
    // 形参state为当前仓库的state
    goodsList(state) {
        // 假如网络不好，返回的是undefined
        return state.searchList.goodsList || []
    },
    trademarkList(state) {
        return state.searchList.trademarkList
    },
    attrsList(state) {
        return state.searchList.attrsList
    }
};

// 对外暴露Store类的一个实例
export default {
    state,
    mutations,
    actions,
    getters
}